<template>
	<view class="pointinvest_container">
		<view class="pointinvest_center">
			<view class="pointinvest_ji">
				积分兑换
			</view>
			<input class="uni-input" placeholder="请输入积分数量" v-model="inputValue"/>
			<view class="pointinvest_line"></view>
			<view style="margin-top: 21rpx;font-size: 30rpx;">
				<text style="color: #999999;">当前积分{{memberInfo.score}}，</text>
				<text style="color: #000000; font-weight: 700;" @click="allBtn">全部兑换</text>
			</view>
		</view>
		<view class="pointinvest_fotter">
			<view :class= "btnShow == true? 'pointinvest_btnY' : 'pointinvest_btnN'" @click="sureBtn">
				确认兑换
			</view>
		</view>
	</view>
</template>

<script>
	import {pointChange} from "../../api/point.js"
	import {getUser} from "../../api/user.js"
	export default{
		data(){
			return{
				inputValue:'',
				btnShow:false,
				memberInfo:{}
			}
		},
		onLoad() {
			// this.getData()
		},
		onShow() {
			// this.getData()
		},
		methods: {
			allBtn(){
				this.inputValue = this.memberInfo.score
			},
			getData(){
				this.post(getUser,{
					user_id:uni.getStorageSync("userInfo").id
				}).then(res => {
						if(res.code == 1){
							this.memberInfo = res.data.member_info	
							this.inputValue = ''
						}
				})
			},
			sureBtn(){
				this.post(pointChange,{
					score:this.inputValue,
					user_id:uni.getStorageSync("userInfo").id
				}).then(res => {
					if(res.code == 1){
						this.msg(res.msg)
						// this.getData()
					}
				})
			}
		},
		watch:{
			inputValue:{
				handler(val,oldval){
					// console.log(val,oldval)
					if(val == ''){
						this.btnShow = false
					}else{
						this.btnShow = true
					}
				}
			},
			deep:true
		}
	}
</script>

<style lang="scss" scoped>
	.uni-input{
		font-size: 30rpx;
		font-weight: 300;
		color: #000000;
		opacity: 1;
	}
	.pointinvest_container{
		padding: 0 30rpx;
		.pointinvest_top{
			display: flex;
			justify-content: space-between;
			margin-top: 56rpx;
			margin-bottom: 99rpx;
			.pointinvest_left{
				font-size: 26rpx;
				font-weight: 300;
				color: #999999;
				opacity: 1;
			}
			.pointinvest_right{
				display: flex;
				image{
					width: 22rpx;
					height: 22rpx;
					margin-top: 7rpx;
					margin-right: 16rpx;
				}
				.pointinvest_yu{
					width: 52rpx;
					height: 37rpx;
					font-size: 26rpx;
					font-weight: 500;
					line-height: 37rpx;
					color: #333333;
					opacity: 1;
				}
				
			}
		}
		.pointinvest_center{
			margin-top: 40rpx;
			.pointinvest_ji{
				width: 300rpx;
				height: 37rpx;
				font-size: 30rpx;
				font-weight: 300;
				line-height: 37rpx;
				color: #999999;
				opacity: 1;
				margin-bottom: 36rpx;
			}
			.pointinvest_line{
				width: 690rpx;
				height: 28rpx;
				border-bottom: 1rpx solid #D5D5D5;
			}
		}
		
	}
	.pointinvest_fotter{
		position: relative;
	}
	.pointinvest_btnN{
		position: absolute;
		top: 114rpx;
		left: 50%;
		transform: translate(-50%,-50%);
		width: 460rpx;
		height: 88rpx;
		background: #008573;
		opacity: 0.3;
		border-radius: 8rpx;
		text-align: center;
		line-height: 88rpx;
		color: #FFFFFF;
		font-size: 30rpx;
	}
	.pointinvest_btnY{
		position: absolute;
		top: 114rpx;
		left: 50%;
		transform: translate(-50%,-50%);
		width: 460rpx;
		height: 88rpx;
		background: #008573;
		opacity: 1;
		border-radius: 8rpx;
		text-align: center;
		line-height: 88rpx;
		color: #FFFFFF;
		font-size: 30rpx;
	}
</style>
